package com.ikun.controller;

import com.ikun.core.pojo.dto.group.UpdateGroup;
import com.ikun.core.utils.R;
import com.ikun.pojo.dto.UserDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


@Slf4j
@Tag(name = "用户管理", description = "用户管理相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Operation(summary = "创建用户")
    @PostMapping
    public R<Object> create(@Validated @RequestBody UserDTO dto) {
        log.info("create user: {}", dto);
        return R.success(dto);
    }

    @Operation(summary = "更新用户")
    @PutMapping("/{id}")
    public Object update(@Validated(UpdateGroup.class) @RequestBody UserDTO dto) {
        log.info("update user: {}", dto);
        return dto;
    }

    @Operation(summary = "查询用户")
    @GetMapping("/search")
    public Object search(@Validated UserDTO dto) {
        log.info("search user: {}", dto);
        return dto;
    }

    @Operation(summary = "删除用户")
    @DeleteMapping("/{id}")
    public R<Object> delete(@PathVariable @NotNull Long id) {
        log.info("delete user: {}", id);
        return R.success(id);
    }
}
